package com.ys.controller.web.finance;

import java.util.HashMap;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ys.config.MenuId;
import com.ys.config.MyConfig;
import com.ys.entity.finance.TcwDepositPlatform;
import com.ys.entity.sys.TbCompanyInfo;
import com.ys.service.sys.CommonApiService;
import com.ys.util.AESUtil;

@Controller
@RequestMapping("/web/finance/tcwDepositPlatform")
public class WebTcwDepositPlatformController {


	@Autowired
	private CommonApiService<TcwDepositPlatform> commonApiService;

	/*
	 * 新增
	 */
	@GetMapping("/toAdd")
	public String toAdd(Model model) throws Exception{

		TcwDepositPlatform entity = new TcwDepositPlatform();
		entity.setCode(commonApiService.getCommonNextUkey(MenuId.TCW_DepositPlatform, "Code"))
				.setStatus(1);
		Map<String, Object> extraParam = new HashMap<String, Object>();
		extraParam.put("platformName", "WorldFirst");
		String aa = commonApiService.toAdd(model,entity, MenuId.TCW_DepositPlatform, extraParam, null);
        
        if ("test".equals(MyConfig.getActive()) || "pro".equals(MyConfig.getActive())) {
			return "finance/tcwDepositPlatform/tcwDepositPlatformAdd";
		} else {
			return aa;
		}
	}



	/*
	 * 编辑
	 */
	@GetMapping("/toEdit")
	public String toEdit(Model model, Long id) throws Exception{

		TcwDepositPlatform entity = new TcwDepositPlatform().setId(id).queryFirst();

		TbCompanyInfo tbCompanyInfo = new TbCompanyInfo().setVid(entity.getCompanyVid()).queryFirst();
		Map<String, Object> extraParam = new HashMap<String, Object>();
		extraParam.put("apiCode", AESUtil.aesDecrypt(entity.getApiCode()));
		extraParam.put("companyVname", tbCompanyInfo.getVname());
		extraParam.put("authorizationTonken", AESUtil.aesDecrypt(entity.getAuthorizationTonken()));

		String aa = commonApiService.toEdit(model, id, new TcwDepositPlatform(), MenuId.TCW_DepositPlatform, extraParam, null);
        
        if ("test".equals(MyConfig.getActive()) || "pro".equals(MyConfig.getActive())) {
			return "finance/tcwDepositPlatform/tcwDepositPlatformEdit";
		} else {
			return aa;
		}
	}

	/*
	 * 详情页
	 */
	@RequiresPermissions("tcwDepositPlatform:view")
	@GetMapping("/toDetail")
	public String toDetail(Model model, Long id){

		TcwDepositPlatform entity = new TcwDepositPlatform().setId(id).queryFirst();
		Map<String, Object> extraParam = new HashMap<String, Object>();
		extraParam.put("apiCode", AESUtil.aesDecrypt(entity.getApiCode()));
		extraParam.put("authorizationTonken", AESUtil.aesDecrypt(entity.getAuthorizationTonken()));

		try {
			return commonApiService.toDetail(model, id, new TcwDepositPlatform(), MenuId.TCW_DepositPlatform, extraParam, null);
		} catch (Exception e) {
			e.printStackTrace();
			return com.bo.vo.W.error(model, e.getMessage());
		}
	}


}
